package main

import (
	"fmt"
	"github.com/pingcap/parser"
	"github.com/pingcap/parser/ast"
	_ "github.com/pingcap/tidb/types/parser_driver"
)

func main() {
	sql := `
CREATE TABLE ` + "`sec_kill`" + ` (
  ` + "`id`" + ` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
  ` + "`amount`" + ` int(10) unsigned NOT NULL COMMENT '总数',
  ` + "`version`" + ` int(10) unsigned NOT NULL COMMENT '版本号',
  PRIMARY KEY (` + "`id`" + `)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
`
	p := parser.New()
	stmtNodes, _, _ := p.Parse(sql, "", "")
	tmp := stmtNodes[0].(*ast.CreateTableStmt)
	fmt.Println(tmp.Table.Name, tmp.Cols[0].Name.String(), tmp.Cols[0].Tp.String(), tmp.Cols[0].Options[2].Expr.(ast.ValueExpr).GetString())
}
